import React, {useContext, useEffect, useState} from "react";
import {
    ActivityIndicator,
    Alert,
    Dimensions,
    ImageBackground,
    Keyboard,
    ScrollView,
    Text,
    TextInput,
    TouchableOpacity,
    View
} from "react-native";
import LocaleContext from "../libs/locale";
import WalletContext from "../libs/wallet";
import under from '../assets/redEnvelopeIndex/under.png';
import SmartXLogo from '../assets/redEnvelopeIndex/SmartXLogo2.png';
import contractImg from '../assets/redEnvelopeIndex/contract.png';
import contractImgEn from '../assets/redEnvelopeIndex/contractEn.png';
import AsyncStorage from "@react-native-async-storage/async-storage";
import {constansts} from "../libs/constansts";
import {GetRedEnvelope, getTxInfo, getTxStatus, QueryRedEnvelope, SendRedEnvelope} from "../libs/nodes";
import Clipboard from "@react-native-community/clipboard";
import Toast from "react-native-simple-toast";
import RedEnvelopeLoad from "./RedEnvelopeLoad";
import RedEnvelopeAlert from "../components/RedEnvelopeAlert";
import {
    addRedEnvelopeGet,
    getRedEnvelopeTxs,
    getTxs as getPendingTxs,
    getTxs2,
    popTx,
    saveTXone
} from "../libs/pendingTxs";
import {formartMoney, toDecimal2} from "../libs/helpers";
import Sound from "react-native-sound";
import {useFocusEffect} from "@react-navigation/native";
import {Icon} from "react-native-elements";
import {addRedRepub} from "./RedEnvelopeRepubDB";

const {width, height,scale} = Dimensions.get("window");

const RedEnvelopeIndex = ({navigation}:any)=>{
    const locale:any = useContext(LocaleContext);
    const wallet: any = useContext(WalletContext);
    const [passwords,setPasswords] = useState('');
    const [num,setNum] = useState('');
    const [amount,setAmount] = useState('0');
    const [lang,setLang] = useState(true)//true为中文 false为英文
    const [sender,setSender] = useState(true)//红包的发送人
    const [loadType,setLoadType] = useState('0');
    const [showRedEnvelopeLoad,setShowRedEnvelopeLoad] = useState(false);//是否显示红包页面
    const [showRedEnvelopeAlert,setRedEnvelopeAlert] = useState(false);//是否显示红包完成提示页面
    const [pkgid,setPkgid] = useState('');
    const [coverTxt,setCoverTxt] = useState("");
    const [traningTokenName,setTTN] = useState(constansts.RedEnvelopeTokenName)

    const [bShowTip,setBShowTip] = useState(false); //是否提示
    //存钱罐
    const [redEnvelopeBalance,setRedEnvelopeBalance] = useState(0);
    var time=0;
    //添加进代币的内容
    const [openRedEnvelopeConAddress,setOpenRedEnvelopeConAddress] = useState('');
    const [openRedEnvelopeTokenName,setOpenRedEnvelopeTokenName] = useState('');
    const [openRedEnvelopeUrl,setOpenRedEnvelopeUrl] = useState('');
    // var openRedEnvelopeConAddress = "";
    // var openRedEnvelopeTokenName = "";
    // var openRedEnvelopeUrl = "";


    //播放音乐

    const playSound = (name:string) =>{
        Sound.setCategory('Playback') // 在静音模式下启用播放'
        let whoosh = new Sound(name, Sound.MAIN_BUNDLE, (error) => {
            whoosh.play((success) => {
                whoosh.release()
            })
        })
    }

    const onCopy = (data:any) => {
        Clipboard.setString(data);
        Toast.show(locale?._('copied') as string);
    };

    const AlertBack = (res:any)=>{
        if(res)
        {
            onCopy(locale._("RedEnvelopeIndex.RedEnvelopeTip1")+"：("+pkgid+")"+"   "+traningTokenName+"\n"+locale._("RedEnvelopeIndex.RedEnvelopeTip2")+"  https://smartxdown.lanzoul.com/b036y4ftc   password:smartx"+"\n"+locale._("RedEnvelopeIndex.RedEnvelopeTip3")+" https://red.smartx.one/#/?pkgid="+pkgid);
        }
        else
        {
            setRedEnvelopeAlert(false);
        }

    }

    const RedEnvelopeLoadBack =  (res: any) => {
        setShowRedEnvelopeLoad(false);
        // console.log(res)
        if (res == "0") {
        } else if (res == "1") {
            playSound("openred.mp3")
            GetRedEnvelope(wallet.address, passwords).then(
                async ()=>{
                    console.log(`openRedEnvelopeConAddress=${openRedEnvelopeConAddress}`)
                    if(openRedEnvelopeConAddress !== "")
                    {
                        for(var i=0;i<(constansts.addTokens).length;i++)
                        {
                            //如果有相同的就只接跳出
                            if( (constansts.addTokens[i] as any).address===openRedEnvelopeConAddress)
                            {
                                break;
                            }
                            //到最后一个并且不相同 添加再退出
                            if((constansts.addTokens[i] as any).address!==openRedEnvelopeConAddress && i === ((constansts.addTokens).length - 1))
                            {
                                (constansts.addTokens as any).push({address:openRedEnvelopeConAddress,url:openRedEnvelopeUrl,desc:openRedEnvelopeTokenName});
                                console.log(`添加后的代币列表:${JSON.stringify(constansts.addTokens)}`)
                                await AsyncStorage.setItem('@addTokens',JSON.stringify(constansts.addTokens as any));
                                break;
                            }
                        }
                        if((constansts.addTokens).length === 0 )
                        {
                            (constansts.addTokens as any).push({address:openRedEnvelopeConAddress,url:openRedEnvelopeUrl,desc:openRedEnvelopeTokenName});
                            console.log(`添加后的代币列表:${JSON.stringify(constansts.addTokens)}`)
                            await AsyncStorage.setItem('@addTokens',JSON.stringify(constansts.addTokens as any));
                        }

                    }

                    navigation.navigate('RedEnvelopeInfo', { pkgid: passwords})
                    await addRedEnvelopeGet(passwords);
                }
            );
        } else if (res == "2") {
            navigation.navigate('RedEnvelopeInfo', { pkgid: passwords});
        }
    }

    const workInterval = async ()=>{
        try {
            constansts.tranRedEnvelope.map(async (item:any,index:any)=>{
                //获取交易状态接口 //状态 -1网络问题 0丢失 1完成 2发送中 3失败 -2没有这个接口
                var txStatus = await getTxStatus(item.hash);
                if(txStatus == -1 || txStatus == 2)
                {
                    return;
                }
                else if (txStatus === -2)
                {
                    let res = await getTxInfo(item.hash);
                    if(res.height === 0)
                    {
                        constansts.RedEnvelopeShowTip = false;
                        setBShowTip(false);
                        Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalse"));
                        await AsyncStorage.setItem('@RedEnvelopetxs', "[]")
                        constansts.tranRedEnvelope.splice(index,1);
                        return;
                    }
                    else if (res.height > 0)
                    {
                        let redInfoTemp = { };
                        try {
                            let res;
                            if(constansts.RedEnvelopeType=="SAT")
                            {
                                redInfoTemp = {hash:constansts.RedEnvelopeHash,num:constansts.RedEnvelopeNumber,total:constansts.RedEnvelopeTotal,bless:constansts.RedEnvelopeBless,tokenName:"",tokenAddress:""};
                                res = await SendRedEnvelope(wallet.address, constansts.RedEnvelopeHash, constansts.RedEnvelopeNumber, constansts.RedEnvelopeTotal,constansts.RedEnvelopeBless,'','');
                            }
                            else
                            {
                                redInfoTemp = {hash:constansts.RedEnvelopeHash,num:constansts.RedEnvelopeNumber,total:constansts.RedEnvelopeTotal,bless:constansts.RedEnvelopeBless,tokenName:constansts.RedEnvelopeTokenName,tokenAddress:constansts.RedEnvelopeTokenAddress};
                                res = await SendRedEnvelope(wallet.address, constansts.RedEnvelopeHash, constansts.RedEnvelopeNumber, constansts.RedEnvelopeTotal,constansts.RedEnvelopeBless,constansts.RedEnvelopeTokenName,constansts.RedEnvelopeTokenAddress);
                            }
                            console.log("pubBack"+JSON.stringify(res))
                            if(res.ret=="-1")
                            {
                                time=0;
                                setBShowTip(false);
                                constansts.tranRedEnvelope.splice(index,1);
                                await AsyncStorage.setItem('@RedEnvelopetxs', "[]")
                                constansts.RedEnvelopeShowTip = false;
                                // Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalseNum"))
                                if(await addRedRepub(redInfoTemp))
                                {
                                    Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalseSave"))
                                }
                                else
                                {
                                    Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalseNum"))
                                }
                                return;
                            }
                            setBShowTip(false);
                            constansts.tranRedEnvelope.splice(index,1);
                            await AsyncStorage.setItem('@RedEnvelopetxs', "[]")
                            constansts.RedEnvelopeShowTip = false;
                            setPkgid(res.dict.pkgid);
                            setNum(constansts.RedEnvelopeNumber);
                            setRedEnvelopeAlert(true);
                            time=0;
                        }catch (e) {
                            // Alert.alert("","红包接口问题"+e);
                            console.log("time="+time);
                            if(time>5)
                            {
                                time=0;
                                setBShowTip(false);
                                constansts.tranRedEnvelope.splice(index,1);
                                await AsyncStorage.setItem('@RedEnvelopetxs', "[]")
                                constansts.RedEnvelopeShowTip = false;
                                // Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalse"))
                                if(await addRedRepub(redInfoTemp))
                                {
                                    Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalseSave"))
                                }
                                else
                                {
                                    Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalseNum"))
                                }
                                return;
                            }
                            time+=1;
                            console.log("发送红包失败,")
                        }
                    }
                    else if ( res === false && (((new Date().getTime())-item.trantime)>(2*60*1000)) )
                    {
                        constansts.RedEnvelopeShowTip = false;
                        setBShowTip(false);
                        Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalse"));
                        await AsyncStorage.setItem('@RedEnvelopetxs', "[]")
                        constansts.tranRedEnvelope.splice(index,1);
                        return;
                    }
                }
                else if(txStatus == 0)
                {
                    constansts.RedEnvelopeShowTip = false;
                    setBShowTip(false);
                    Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalse"));
                    await AsyncStorage.setItem('@RedEnvelopetxs', "[]")
                    constansts.tranRedEnvelope.splice(index,1);
                    return;
                }
                else if(txStatus == 1)
                {
                    let redInfoTemp = { };
                    try {
                        let res;
                        if(constansts.RedEnvelopeType=="SAT")
                        {
                            redInfoTemp = {hash:constansts.RedEnvelopeHash,num:constansts.RedEnvelopeNumber,total:constansts.RedEnvelopeTotal,bless:constansts.RedEnvelopeBless,tokenName:"",tokenAddress:""};
                            res = await SendRedEnvelope(wallet.address, constansts.RedEnvelopeHash, constansts.RedEnvelopeNumber, constansts.RedEnvelopeTotal,constansts.RedEnvelopeBless,'','');
                        }
                        else
                        {
                            redInfoTemp = {hash:constansts.RedEnvelopeHash,num:constansts.RedEnvelopeNumber,total:constansts.RedEnvelopeTotal,bless:constansts.RedEnvelopeBless,tokenName:constansts.RedEnvelopeTokenName,tokenAddress:constansts.RedEnvelopeTokenAddress};
                            res = await SendRedEnvelope(wallet.address, constansts.RedEnvelopeHash, constansts.RedEnvelopeNumber, constansts.RedEnvelopeTotal,constansts.RedEnvelopeBless,constansts.RedEnvelopeTokenName,constansts.RedEnvelopeTokenAddress);
                        }
                        console.log("pubBack"+JSON.stringify(res))
                        if(res.ret=="-1")
                        {
                            time=0;
                            setBShowTip(false);
                            constansts.tranRedEnvelope.splice(index,1);
                            await AsyncStorage.setItem('@RedEnvelopetxs', "[]")
                            constansts.RedEnvelopeShowTip = false;
                            // Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalseNum"))
                            if(await addRedRepub(redInfoTemp))
                            {
                                Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalseSave"))
                            }
                            else
                            {
                                Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalseNum"))
                            }
                            return;
                        }
                        setBShowTip(false);
                        constansts.tranRedEnvelope.splice(index,1);
                        await AsyncStorage.setItem('@RedEnvelopetxs', "[]")
                        constansts.RedEnvelopeShowTip = false;
                        setPkgid(res.dict.pkgid);
                        setNum(constansts.RedEnvelopeNumber);
                        setRedEnvelopeAlert(true);
                        time=0;
                    }catch (e) {
                        // Alert.alert("","红包接口问题"+e);
                        console.log("time="+time);
                        if(time>5)
                        {
                            time=0;
                            setBShowTip(false);
                            constansts.tranRedEnvelope.splice(index,1);
                            await AsyncStorage.setItem('@RedEnvelopetxs', "[]")
                            constansts.RedEnvelopeShowTip = false;
                            // Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalse"))
                            if(await addRedRepub(redInfoTemp))
                            {
                                Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalseSave"))
                            }
                            else
                            {
                                Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalseNum"))
                            }
                            return;
                        }
                        time+=1;
                        console.log("发送红包失败,")
                    }
                }
                else if(txStatus == 3)
                {
                    constansts.RedEnvelopeShowTip = false;
                    setBShowTip(false);
                    Alert.alert("",locale._("RedEnvelopeInfo.AlertSendFalse"));
                    await AsyncStorage.setItem('@RedEnvelopetxs', "[]")
                    constansts.tranRedEnvelope.splice(index,1);
                    return;
                }
            })
        }catch (e) {
            console.log("RedEnvelopeSendfalse==>"+e)
        }
    }

    useEffect(() => {
        let t: NodeJS.Timeout;
        const work = async () => {
            constansts.tranRedEnvelope = await getRedEnvelopeTxs();
            constansts.tranRedEnvelope.length > 0 ? setBShowTip(true) : setBShowTip(false);
            constansts.tranRedEnvelope.length > 0 ? (constansts.RedEnvelopeShowTip=true) : (constansts.RedEnvelopeShowTip=false);
            (constansts.RedEnvelopeHash as any) = await AsyncStorage.getItem('@RedEnvelopeHash');
            (constansts.RedEnvelopeNumber as any) = await AsyncStorage.getItem('@RedEnvelopeNum');
            (constansts.RedEnvelopeTotal as any) = await AsyncStorage.getItem('@RedEnvelopeAmount');
            constansts.RedEnvelopeType = await AsyncStorage.getItem("@RedEnvelopeType");
            constansts.RedEnvelopeTokenName = await AsyncStorage.getItem("@RedEnvelopeTokenName");
            setTTN(constansts.RedEnvelopeTokenName);
            constansts.RedEnvelopeTokenAddress = await AsyncStorage.getItem("@RedEnvelopeTokenAddress");
            t = setInterval(workInterval, 5000);
        }
        work();
        return ()=>{
            clearInterval(t);
        }

    },[]);

    useEffect(()=>{
        const work = async () => {
            var lang = await AsyncStorage.getItem('@lang');
            if(lang=='zh')
            {
                setLang(true);
            }
            else
            {
                setLang(false);
            }
        }

        work();
    },[]);

    const showNeedExcuteContent=()=>{
        return locale?._('RedEnvelopeIndex.Tip')+"  "+locale._("Number")+"："+constansts.RedEnvelopeNumber + '  丨 '+locale._("Total")+'：' + toDecimal2(formartMoney(constansts.RedEnvelopeTotal,2))+" "+(traningTokenName|| "")+"";
    }

    useFocusEffect(
        React.useCallback(() => {
            let t:any;
            let onOFF = true;
            const inwork = async()=>{
                var txx = await getTxs2();
                await txx.map(async (tx:any,index:number)=>{
                    let heightNow = "0";
                    if(tx.height !== -1 )
                    {

                    }
                    else {
                        var txStatus = await getTxStatus(tx.hash);
                        if(txStatus == -1 || txStatus == 2)
                        {
                            return;
                        }
                        else if (txStatus === -2)
                        {
                            let res = await getTxInfo(tx.hash);
                            if(res.height === 0)
                            {
                                txx[index].height = 0;
                                await saveTXone(txx[index], "modify");
                            }
                            else if (res.height > 0)
                            {
                                await popTx(tx.hash);
                            }
                            else if ( res === false && (((new Date().getTime())-tx.trantime)>(2*60*1000)) )
                            {
                                txx[index].height = -2;
                                await saveTXone(txx[index], "modify");
                                return;
                            }
                        }
                        else if(txStatus == 0)
                        {
                            txx[index].height = -2;
                            await saveTXone(txx[index], "modify");
                            return;
                        }
                        else if(txStatus == 1)
                        {
                            await popTx(tx.hash);
                        }
                        else if(txStatus == 3)
                        {
                            txx[index].height = 0;
                            await saveTXone(txx[index], "modify");
                        }
                    }
                })

                try {
                    const txs = await getPendingTxs();
                } catch (e) {
                    console.log('getPendingTxs inwork:', e);
                }
                t = null;
                if(!onOFF)
                {
                    return ;
                }
                t = setTimeout(()=>{inwork()},10*1000);
            }
            inwork();
            return ()=> {
                onOFF = false;
                clearTimeout(t)
            };
        }, [])
    );

    //获取发送失败的红包的数据库

    return(
        <View style={{position:"relative",flex:1}}>
            <TouchableOpacity
                onPress={()=>{
                    navigation.navigate("RedEnvelopeRepub")
                }}
                activeOpacity={0.7}
                style={{
                    position:"absolute",justifyContent:"center",alignItems:"center",
                    width:50,height:50,borderRadius:25,backgroundColor:"#ff3221",top:0,right:15,zIndex:88
                }}>
                <Icon type='font-awesome-5' name="envelope" color={'#e3f5a1'} size={25}/>
            </TouchableOpacity>
            <View style={{backgroundColor:"#ff3221",width:width,height:0.7*height}}>
                {/*<View style={{height:0.04*height,width:width,marginTop:0.07*height,flexDirection:"row"}}>*/}
                {/*    <Text style={{height:0.04*height,fontSize:width/360*15,color:"white",lineHeight:0.04*height,alignSelf:"center"}}>*/}
                {/*        红包存钱罐余额: {toDecimal2(formartMoney(redEnvelopeBalance.toString(),2))} SAT*/}
                {/*    </Text>*/}
                {/*    <View style={{flex:1,height:0.04*height,justifyContent:"center"}}>*/}
                {/*        <TouchableOpacity style={{justifyContent:"center"}}>*/}
                {/*            <Text style={{alignSelf:"flex-end",paddingLeft:width*0.05,color:"white",backgroundColor:"orange",*/}
                {/*                height:0.03*height,borderRadius:0.015*height,borderBottomRightRadius:0,borderTopRightRadius:0}}>充值存钱罐 ></Text>*/}
                {/*        </TouchableOpacity>*/}
                {/*    </View>*/}
                {/*</View>*/}
                {/* marginTop:height*0.01 */}
                <ImageBackground source={SmartXLogo} style={{width:0.5*width,height:1/6.07*0.5*width,alignSelf:"center",marginTop:height*0.12}}/>
                <Text style={{marginTop:0.05*height,alignSelf:"center",fontSize:width/360*15,color:"#e3f5a1"}}>
                    ——{(locale as any)._("RedEnvelopeIndex.Title1")}——
                </Text>
                <TouchableOpacity
                    onPress={()=>{navigation.navigate('RedEnvelope');}}
                    activeOpacity={0.8}
                    style={{width:0.8*width,height:0.07*height,backgroundColor:"#ffdfa6",marginTop:0.05*height,
                    alignSelf:"center",borderRadius:width*0.02,justifyContent:"center",alignItems:"center"}}>
                    <Text style={{fontSize:width/360*20,letterSpacing:lang?width*0.03:0,color:"#9d3212"}}>
                        {(locale as any)._("RedEnvelopeIndex.Type")}
                    </Text>
                </TouchableOpacity>
                <Text style={{marginTop:0.05*height,alignSelf:"center",fontSize:width/360*15,color:"#e3f5a1"}}>
                    ——{(locale as any)._("RedEnvelopeIndex.Title2")}——
                </Text>
                <View style={{width:0.8*width,height:0.07*height,backgroundColor:"white",alignSelf:"center",borderRadius:width*0.02,marginTop:height*0.05,alignItems:"center",flexDirection:"row"}}>
                    <TextInput
                        style={{width:0.5*width,padding:0,fontSize:width/360*17,marginLeft:width*0.05,borderRightWidth:5/scale,borderRightColor:"#d1cfa6"}}
                        placeholder={(locale as any)._("RedEnvelopeIndex.PlaceHold")}
                        value={passwords}
                        onChangeText={(value) => {
                            setPasswords(value);
                        }}
                    />
                    <TouchableOpacity style={{flex:1,alignItems:"center"}} onPress={
                        async () => {
                        Keyboard.dismiss();
                        if (passwords == "") {
                            return;
                        }
                        var password ="";
                        if(passwords.indexOf("(")!==-1&&passwords.indexOf(")")!==-1)
                        {
                            password = passwords.slice(passwords.indexOf("(")+1,passwords.indexOf(")"));
                            setPasswords(password);
                        }
                        else
                        {
                            password=passwords;
                        }

                        try {
                            var result: any = await QueryRedEnvelope(password);
                            var sender = result.dict.nickname || result.dict.sender;
                            setOpenRedEnvelopeConAddress (result.dict.type || "");
                            setOpenRedEnvelopeTokenName(result.dict.coinname || "");
                            setOpenRedEnvelopeUrl ( result.dict.url || "");
                            setCoverTxt(result.dict.desc);
                            if(sender!=="")
                            {
                                setSender(sender);
                                var temp=0;//0是红包还有可以强，并且没抢过这个红包。   1是抢过这个红包了。   2是红包没了，手速慢了
                                if(result.pkgitems.length<parseInt(result.dict.number))//红包还有，里面区分0和1
                                {
                                    if(result.pkgitems.length!=0)
                                    {
                                        for(var i=0;i<result.pkgitems.length;i++)
                                        {
                                            if(result.pkgitems[i].getter==wallet.address)
                                            {
                                                temp=1;
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        temp=0;
                                    }
                                }
                                else if(result.pkgitems.length>=parseInt(result.dict.number)) //红包没了 ，里面区分抢过了1和没抢过2
                                {
                                    if(result.pkgitems.length!=0)
                                    {
                                        for(var i=0;i<result.pkgitems.length;i++)
                                        {
                                            if(result.pkgitems[i].getter==wallet.address)
                                            {
                                                temp=1;
                                                break;
                                            }
                                            if(i==result.pkgitems.length-1)
                                            {
                                                temp=2;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        temp=2;
                                    }
                                }
                                else
                                {
                                    temp=0;
                                }
                                if(temp==1)
                                {
                                    navigation.navigate('RedEnvelopeInfo', { pkgid: password});
                                }
                                else{
                                    setLoadType(temp.toString())
                                    setShowRedEnvelopeLoad(true);
                                }

                            }
                            else
                            {
                                Alert.alert("",locale._('RedEnvelopeIndex.RedEnvelopeWarn'));
                            }
                        }catch (e) {
                            console.log("抢红包错误==》"+e)
                            return ;
                        }

                    }}>
                        <Text style={{fontSize:width/360*18,color:passwords?"#9d3212":"grey"}}>{(locale as any)._("RedEnvelopeIndex.Get")}</Text>
                    </TouchableOpacity>
                </View>
                <View style={{flex:1,alignItems:"center"}}>
                    {
                        bShowTip ?
                        <View style={{flexDirection: "row", marginTop: 20, alignItems: "center"}}>
                            <ActivityIndicator
                                animating={true}
                                color={'yellow'}
                                size={'small'}
                            />
                            <Text style={{
                                marginLeft: 10,
                                fontSize: width/360*13,
                                color: 'yellow'
                            }}>{showNeedExcuteContent()}</Text>
                        </View>
                        : null
                    }
                    <TouchableOpacity onPress={()=>{navigation.navigate('RedEnvelopeList');}} activeOpacity={0.8}>
                        <Text style={{color:"white",fontSize:width/360*17,marginTop:constansts.RedEnvelopeShowTip?10:height*0.06}}>{(locale as any)._("RedEnvelopeIndex.Record")}</Text>
                    </TouchableOpacity>
                </View>
            </View>
            <View style={{width:width,height:0.3*height,marginTop:-height*0.03,backgroundColor:"pink"}}>
                <ImageBackground source={under} style={{width:width,height:0.35*height}}>

                    <View style={{marginTop:height*0.05,width:width*0.9,height:height*0.26,alignSelf:"center",backgroundColor:"#fff",borderRadius:width*0.03,paddingLeft:width*0.05}}>
                        <ScrollView>
                        <Text style={{color:"black",fontWeight:"bold",fontSize:width/360*18,marginTop:height*0.015}}>
                            {(locale as any)._("RedEnvelopeIndex.Contract")}
                        </Text>
                        <TouchableOpacity onPress={()=>{navigation.navigate('Pool')}} activeOpacity={0.7}>
                            <ImageBackground source={lang?contractImg:contractImgEn} style={{width:width*0.8,height:0.16*height,marginTop:height*0.01}}>
                            </ImageBackground>
                        </TouchableOpacity>
                        </ScrollView>
                    </View>
                </ImageBackground>
            </View>
            <RedEnvelopeLoad visible={showRedEnvelopeLoad} back={RedEnvelopeLoadBack} sender={sender} loadType={loadType} bless={coverTxt}/>
            <RedEnvelopeAlert visible={showRedEnvelopeAlert} back={AlertBack} pkgid={pkgid} num={constansts.RedEnvelopeNumber} total={constansts.RedEnvelopeTotal} coinname={constansts.RedEnvelopeTokenName}/>
        </View>
    );
}
export  default RedEnvelopeIndex;
